<template>
  <div>
    <van-form @submit="login">
      <van-field
        v-model="user.phone"
        name="账号"
        label="账号"
        placeholder="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="user.password"
        type="user.password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="warning" native-type="submit">登录</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
import { reqlogin } from "../../http/http";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      user: {
        phone: "",
        password: ""
      }
    };
  },
  methods: {
    ...mapActions({
      changeInfo: "changeInfo"
    }),
    login() {
      reqlogin(this.user).then(res => {
        if (res.data.code === 200) {
          Toast(res.data.msg);
          this.changeInfo(res.data.list);
          this.$router.push("/index/home");
        }
      });
    }
  }
};
</script>